(function ($) {
	var preData = {}
	var keys = {},statusKey=''
	var pageArr=[],icon="",titleStr="";
	var method = '',kyPth=''
	var TomcatUrl = JSON.parse(localStorage.getItem('$user')).TomcatUrl;
	$.init();
	$.plusReady(function() {
		baseSetup();
	})
	if (!mui.os.plus) {
		baseSetup()
	}
	
	function getDetailData(){
		//parr 病区Id^开始日期^结束日期^论文题()
		var pdict = {'id':preData['rw']}
		var paramDict = {'method':method,'params':JSON.stringify(pdict),'type':'RecMethod'}
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			var dataArr = result.data
			updateUI(dataArr)
			
		}, function(errorStr) {
		 	mui.toast(errorStr)
		});
	}
	
	//发表论文备案
	function updateUI(dict){
		var statusText = dict[statusKey]
		var statusIcon = ''
		var commitText = '提交时间：'
		if (statusText == '已保存') {
			statusIcon = 'nur-statusS'
			commitText = '保存时间：'
		}else if (statusText == '已提交') {
			statusIcon = 'nur-statusR'
		}else if (statusText == '已审核') {
			statusIcon = 'nur-statusA'
		}else if(statusText == '驳回'){
			statusIcon = 'nur-statusB'
		}
		$('#applyer')[0].innerHTML = dict[keys['applyer']]+' '+keys['titleStr']
		//$('#appLoc')[0].innerHTML = '申请科室：CCU'
		$('#appLoc')[0].style.display = 'none'
		$('#appDate')[0].innerHTML = commitText+dict[keys['applyDate']]
		$('#statusIcon')[0].innerHTML = '<div class="nurfont '+statusIcon+'"></div>'
		var htmls = ''
		var group = 1
		for (var i = 0; i < pageArr.length;i++) {
			var oneData = pageArr[i];
			var title = oneData['title']
			var keyStr = oneData['key']
			var keyType = oneData['type']
			var valueStr = dict[keyStr];
			var html = '<li class="mui-table-view-cell"><div class="leftText">'+title+'：</div><div class="rightText">'
			if (keyType == 'auth') {
				html += getAuthorHtml(valueStr)
			}else if (keyType == 'file') {
				html +=getDetailFileHtml(valueStr,group,TomcatUrl,kyPth)
				group += 1
			}else{
				html += valueStr
			}
			html +='</div></li>'
			htmls += html
		}
		$('#middleUL')[0].innerHTML = htmls
		
		var approveClass = ''
		var approveText = ''
		var approveIcon = ''
		var commitText = '提交'
		if (statusText == '已保存') {
			approveClass = ''
			approveText = '待提交'
			approveIcon = 'nur-nocheck'
			commitText = '保存'
		}else if (statusText == '已提交') {
			approveClass = 'dealing';
			approveText = '审核中';
			approveIcon = 'nur-zanting'
		}else if (statusText == '已审核') {
			approveClass = 'pass';
			approveText = '审核通过';
			approveIcon = 'nur-correct'
		}else if (statusText == '驳回') {
			approveText = '审核不通过'
			approveClass = 'refuse'
			approveIcon = 'nur-error'
		}
		
		var AuditOpinion = dict['AuditOpinion']!= undefined?dict['AuditOpinion']:''
		//流程  AuditDate审核日期 AuditTime审核时间 AuditOpinion审核意见 Auditor审核人id AuditName审核人姓名
		var processHtml = '<li class="mui-table-view-cell '+approveClass+'">'+
				'<div class="processIcon"><div class="nurfont '+approveIcon+'"></div></div>'+
				'<div class="oneline">'+
					'<div class="dealName mui-ellipsis">'+ dict['AuditorName']+'  '+approveText+'</div>'+
					'<div class="dealDate">'+dict['AuditDate']+' '+dict['AuditTime']+'</div>'+
				'</div>'+
				'<div class="dealLoc mui-ellipsis">'+AuditOpinion+'</div>'+
			'</li>'+
			'<li class="mui-table-view-cell">'+
				'<div class="processIcon"><div class="nurfont nur-nocheck"></div></div>'+
				'<div class="oneline">'+
					'<div class="dealName mui-ellipsis">'+ dict['CreatorName']+'  '+commitText+'</div>'+
					'<div class="dealDate">'+dict['CreateDate']+' '+dealUndefined(dict['CreateTime'])+'</div>'+
				'</div>'+
				'<div class="dealLoc mui-ellipsis">'+dict['CreatorWard']+'</div>'+
			'</li>'
		$('#processUL')[0].innerHTML = processHtml
		setupDetailFileTap('middleUL')
	}
	
	function baseSetup(){
		$('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		mui.previewImage();
		var self = plus.webview.currentWebview()
		keys = self.keys
		var data = self.data
		preData = data
		
		pageArr = keys['pageArr']
		var pageData = getDetailPageData(self.pageType)
		statusKey = getKyStatusKey(self.pageType);
		kyPth = getKyPath(self.pageType)+'/'+preData['rw']+'/'
		method = pageData['method']
		getDetailData();
	}
	
})(mui)